<?php
session_start();
require_once("../db_connect.php");
$thread_contribute_name = array();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet"  href="../../css/css.css" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.corner.js"></script>
<script type="text/javascript">
//未入力項目をチェックする
function chValie() {
// 入力必須項目（「,」で区切って追加可能）
ess = new Array("volunteer_Name","age","Location","access","Conditions","application_number");
for(i=0; i<ess.length; i++) {
 txt = document.volForm.elements[ess[i]].value;
 if(txt == "") {
   alert("未入力の項目があります");
   return false;
 }
}
return true;
}
</script>
<title>Insert title here</title>
</head>
    <body>
	<div id="container">
		<div id="header" class="box4">
			<div id="logo">
			</div>
			<div id="header_box" >
				<div id="title">
					ボランティア掲示システム
				</div>
				<div id="search_box">
					<form method="post" action="#">
					<input type="text" name="search_word">
					<input type="submit" value="検索する">
					</form>
				</div>
			</div>
		</div>
		<div id="rightnavi" class="box">
		<?php if(empty($_SESSION["user_name"])&&empty($_SESSION["user_id"])){?>
			<form method="post" action="./PHP/UserLogin.php">
				<p>ID：　　<input type="text" name="name" size="10"></p>
				<p>PASS：<input type="text" name="email" size="10"></p>
				<p>　　　　　　	<input type="submit" value="ログイン"></p>
			</form>
			<p>　　　　<button type="button" >新規会員登録</button></a></p>
		<?php }else{?>
				<p><a href="user_information.php">会員情報表示</a></p>
				<p><a href="user_updata.php">会員情報変更</a></p>
				<p><a href="#">パスワード変更</a></p>
				<p><a href="#">履歴</a></p>
				<p><a href="#">退会</a></p>
				<p><a href="user_logout.php">ログアウト</a></p>
				<br />
		<?php }?>
		<h3>掲示板</h3>
				<ul class="menu_margin">
	<div id="thread_title_look">
<?php

	//スレッド項目取得
	$sql = "SELECT t.thread_id,count(thread_name) as thread_count,t.thread_name,max(r.response_date) as response_date,t.thread_id FROM thread AS t LEFT OUTER JOIN response AS r ON t.thread_id = r.thread_id group by t.thread_name order by response_date desc limit 0,5";
	$sth = $db->query($sql);
	if (DB::isError($sth)) {
	  exit($sth->getMessage());
	}

	//スレッド表示
	while ($data = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
	  echo "<li><a href='./response.php?thread_id=".$data['thread_id']."'>";
	  echo mb_strlen($data['thread_name'])>=9?mb_substr($data['thread_name'],0,9)."...":$data['thread_name'];
	  echo "</a></li>";
	}
?>
</div>
				</ul>
				<div id="more"><a href="./thread.php">もっと見る...</a></div>
	</div>
<div id="main"  class="box3">
<h2 align="center">最新ボランティア情報</h2>
	<br /><br />
	<link rel="stylesheet"  href="../../css/table_css.css" type="text/css" />
	<table class="table2" align="center">
	<div align="right" >
	全て｜	申請中	｜	活動済
	</div>
	<tr>
	<th></th>
	<th>ボランティア名</th>
	<th>更新日</th>
	<th>活動終了日</th>
	<th></th>
	</tr>
<?php
	//ボランティア情報を更新日が最新のから5件ずつ表示するSQL(タイトルのみ)
	$sql = "SELECT volunteer_information_id,volunteer_name,activity_date,end_time
			FROM volunteer_information
			order by updata_date desc";// limit 0,5

	$sth = $db->query($sql);

	if (DB::isError($sth)) {
	  exit($sth->getMessage());
	}

	//ボランティア情報を5件ずつ表示する
	//詳しく知りたい場合は「詳細」ボタンを押す↓
	//display_volunteer_informatino.phpで詳細を表示する。


	$count = 0;
	while ($data = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
		$count = $count + 1;
		$volunteer1 = $data['volunteer_name'];
		$volunteer2 = $data['activity_date'];
		$volunteer3 = $data['end_time'];
		//echo "<a href='../volunteer_function/display_volunteer_information.php?volunteer_information_id=".$data['volunteer_information_id']."'>詳細</a>";

	}

	print("
		<tr>
		<td>$count</td>
		<td>$volunteer1</td>
		<td>$volunteer2</td>
		<td>$volunteer3</td>
		<td><a href='../volunteer_function/display_volunteer_information.php?volunteer_information_id=".$data['volunteer_information_id']."'>詳細</a></td>

		</tr>
	")
?>
</div>
<div id="space"></div>
</div>
    </body>
</html>